var plane = $(".plane"),
	universe = $(".universe"),
	space = $(".space"),
	start_place = $(".start_place");

function running() {
	start_place.before("<div class='space'></div>");
	space = $(".space");
	plane.html("");
	plane.append("<img src='images/game_start/plane.png '>")

	space.addClass("space_move")
	start_place.addClass("move");

	// setTimeout(() => {
	//     start_place.remove();
	// }, 3000);
	start_place.on("animationend", function() {
		start_place.remove();
	})

	var timer = setInterval(() => {
		space.before("<div class='space_rock'></div>");
		for(var i = 0; i < 5; i++) {
			var rd_num = Math.ceil(Math.random() * 5),
				rock_top = Math.floor(Math.random() * 85),
				rock_left = Math.floor(Math.random() * 75),
				space_rock = $(".space_rock");
			var new_rock = document.createElement("img");
			space_rock.append(new_rock)
			$(new_rock).attr("src", "images/game_start/rock" + rd_num + ".png");
			$(new_rock).css("top", rock_top + "%");
			$(new_rock).css("left", rock_left + "%");
		}
		space_rock.addClass("space_move");
		space_rock.on("animationend", function() {
			space_rock.eq(0).remove();
		})
	}, 1300);
}

// 何绍靖
var js_plane = document.querySelector(".plane");
var running_bool = true;
mask_close.addEventListener("click", function() {
	mYanimate(universe_mask, {
		"opacity": 0
	}, 50, function() {
		if(running_bool) {
			running_bool = false;
			running();
		}
		document.addEventListener("touchstart", function(e) {
			var pagex = e.targetTouches[0].clientX;
			document.addEventListener("touchmove", function(e) {
				console.log(js_plane.style.left);

				var pagex_move = e.targetTouches[0].clientX;
				var x = pagex_move - pagex;
				var _left = js_plane.offsetLeft;

				js_plane.style.left = x + _left + "px";
				console.log(js_plane.offsetLeft);
				// console.log(document.querySelector(".plane"));
			})
		})
	});
})